package com.crazyauntzhang.easyshopbackend.controller;

import com.crazyauntzhang.easyshopbackend.domain.*;
import com.crazyauntzhang.easyshopbackend.request.AddStockRequest;
import com.crazyauntzhang.easyshopbackend.request.DeleteStockRequest;
import com.crazyauntzhang.easyshopbackend.request.FindStockRequest;
import com.crazyauntzhang.easyshopbackend.result.ResponseResult;
import com.crazyauntzhang.easyshopbackend.service.*;
import com.crazyauntzhang.easyshopbackend.util.FormatChecker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Field;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class StockController {

	private final ItemService itemService;
	private final StockService stockService;
	private final SupplementFlowService supplementFlowService;
	private final SupplierService supplierService;
	private final TurnoverFlowService turnoverFlowService;

	@Autowired
	public StockController(ItemService itemService,
						   StockService stockService,
						   SupplementFlowService supplementFlowService,
						   SupplierService supplierService,
						   TurnoverFlowService turnoverFlowService) {
		this.itemService = itemService;
		this.stockService = stockService;
		this.supplementFlowService = supplementFlowService;
		this.supplierService = supplierService;
		this.turnoverFlowService = turnoverFlowService;
	}

	/**
	 * 进入库存页查询Top20销量商品库存
	 *
	 * @return 【Top20销量商品库存】【无商品售出】
	 */
	@PostMapping("/show20StocksWithSalesAndMainSupplier")
	public ResponseResult<Object> show20StocksWithSalesAndMainSupplier() throws IllegalAccessException {
		//查询Top20销量商品的库存，如果查不到则返回异常响应
		List<String> stockList = turnoverFlowService.findTop20SalesIn30DaysWithBarcode();
		if (stockList.isEmpty())
			return new ResponseResult<>(10404, "Sales Not Found");
		//遍历查询到的库存，添加更多信息
		List<Object> findStocksList = new ArrayList<>();
		for (String itemBarcode : stockList) {
			Item item = itemService.findItemByBarcode(itemBarcode);
			Stock stock = stockService.findStock(itemBarcode);
			Double salesIn30Days = turnoverFlowService.findSalesIn30Days(itemBarcode);
			Supplier mainSupplier = supplierService.findMainSupplier(itemBarcode);
			Map<String, Object> findStockMap = new HashMap<>();
			Class<? extends Item> itemClass = item.getClass();
			Field[] itemClassDeclaredFields = itemClass.getDeclaredFields();
			for (Field field : itemClassDeclaredFields) {
				field.setAccessible(true);
				findStockMap.put(field.getName(), field.get(item));
			}
			findStockMap.put("quantity", stock.getQuantity());
			findStockMap.put("salesIn30Days", salesIn30Days);
			if (mainSupplier==null)
				findStockMap.put("mainSupplier", "/");
			else
				findStockMap.put("mainSupplier", mainSupplier.getSupplierName());
			findStocksList.add(findStockMap);
		}
		return new ResponseResult<>(10200, "OK", findStocksList);
	}

	/**
	 * 进货入库时查询商品
	 *
	 * @param findStockRequest 请求体对象
	 * @return 【商品信息】【未查到商品】
	 */
	@Deprecated
	@PostMapping("/findItem")
	public ResponseResult<Object> findItem(@RequestBody FindStockRequest findStockRequest) {
		//获取请求体中的条码，查询对应商品
		String itemBarcode = findStockRequest.getItemBarcode();
		Item item = itemService.findItemByBarcode(itemBarcode);
		if (item == null)
			return new ResponseResult<>(10404, "Item Not Found");
		return new ResponseResult<>(10200, "OK", item);
	}

	/**
	 * 按条码或名称查询库存
	 *
	 * @param findStockRequest 请求体对象
	 * @return 响应体
	 */
	@Deprecated
	@PostMapping("/findStock")
	public ResponseResult<Object> findStock(@RequestBody FindStockRequest findStockRequest)
			throws IllegalAccessException {
		List<Object> findStockList = new ArrayList<>();

		String itemBarcodeOrName = findStockRequest.getItemBarcodeOrName();

		if (FormatChecker.isNumber(itemBarcodeOrName)) {
			Item item = itemService.findItemByBarcode(itemBarcodeOrName);
			if (item == null)
				return new ResponseResult<>(10404, "Item Not Found");

			Stock stock = stockService.findStock(itemBarcodeOrName);
			if (stock == null)
				return new ResponseResult<>(10404, "Stock Not Found");

			Map<String, Object> findStockMap = new HashMap<>();
			Class<? extends Item> itemClass = item.getClass();
			Field[] itemClassDeclaredFields = itemClass.getDeclaredFields();
			for (Field field : itemClassDeclaredFields) {
				field.setAccessible(true);
				findStockMap.put(field.getName(), field.get(item));
			}
			findStockMap.put("quantity", stock.getQuantity());
			findStockList.add(findStockMap);
		} else {
			List<Item> itemList = itemService.findItemByName(itemBarcodeOrName);
			if (itemList.isEmpty())
				return new ResponseResult<>(10404, "Item Not Found");
			for (Item item : itemList) {
				String barcode = item.getItemBarcode();
				Stock stock = stockService.findStock(barcode);

				Map<String, Object> findStockMap = new HashMap<>();
				if (stock == null) {
					findStockMap.put("itemBarcodeOrName", itemBarcodeOrName);
					findStockList.add(findStockMap);
					return new ResponseResult<>(10404, "Stock Not Found", findStockList);
				}
				Class<? extends Item> itemClass = item.getClass();
				Field[] itemClassDeclaredFields = itemClass.getDeclaredFields();
				for (Field field : itemClassDeclaredFields) {
					field.setAccessible(true);
					findStockMap.put(field.getName(), field.get(item));
				}
				findStockMap.put("quantity", stock.getQuantity());
				findStockList.add(findStockMap);
			}
		}
		return new ResponseResult<>(10200, "OK", findStockList);
	}

	/**
	 * 按条码查询库存
	 *
	 * @param findStockRequest 请求体对象
	 * @return 响应体
	 */
	@Deprecated
	@PostMapping("/findStockByBarcode")
	public ResponseResult<Object> findStockByBarcode(@RequestBody FindStockRequest findStockRequest)
			throws IllegalAccessException {
		List<Object> findStockList = new ArrayList<>();

		String itemBarcode = findStockRequest.getItemBarcode();

		Item item = itemService.findItemByBarcode(itemBarcode);
		if (item == null)
			return new ResponseResult<>(10404, "Item Not Found");

		Stock stock = stockService.findStock(itemBarcode);
		if (stock == null)
			return new ResponseResult<>(10404, "Stock Not Found");

		Map<String, Object> findStockMap = new HashMap<>();
		Class<? extends Item> itemClass = item.getClass();
		Field[] itemClassDeclaredFields = itemClass.getDeclaredFields();
		for (Field field : itemClassDeclaredFields) {
			field.setAccessible(true);
			findStockMap.put(field.getName(), field.get(item));
		}
		findStockMap.put("quantity", stock.getQuantity());
		findStockList.add(findStockMap);
		return new ResponseResult<>(10200, "OK", findStockList);
	}

	/**
	 * 按名称查询库存
	 *
	 * @param findStockRequest 请求体对象
	 * @return 响应体
	 */
	@Deprecated
	@PostMapping("/findStockByName")
	public ResponseResult<Object> findStockByName(@RequestBody FindStockRequest findStockRequest)
			throws IllegalAccessException {
		List<Object> findStockList = new ArrayList<>();

		String itemName = findStockRequest.getItemName();

		List<Item> itemList = itemService.findItemByName(itemName);
		if (itemList.isEmpty())
			return new ResponseResult<>(10404, "Item Not Found");
		for (Item item : itemList) {
			String barcode = item.getItemBarcode();
			Stock stock = stockService.findStock(barcode);

			Map<String, Object> findStockMap = new HashMap<>();
			if (stock == null) {
				findStockMap.put("itemBarcodeOrName", itemName);
				findStockList.add(findStockMap);
				return new ResponseResult<>(10404, "Stock Not Found", findStockList);
			}
			Class<? extends Item> itemClass = item.getClass();
			Field[] itemClassDeclaredFields = itemClass.getDeclaredFields();
			for (Field field : itemClassDeclaredFields) {
				field.setAccessible(true);
				findStockMap.put(field.getName(), field.get(item));
			}
			findStockMap.put("quantity", stock.getQuantity());
			findStockList.add(findStockMap);
		}
		return new ResponseResult<>(10200, "OK", findStockList);
	}

	/**
	 * 按条码或名称查询带30天销量和主供应商的库存
	 *
	 * @param findStockRequest 请求体对象
	 * @return 响应体
	 */
	@PostMapping("/findStockWithSalesAndMainSupplier")
	public ResponseResult<Object> findStockWithSalesAndMainSupplier(@RequestBody FindStockRequest findStockRequest)
			throws IllegalAccessException {
		List<Object> findStockList = new ArrayList<>();
		//获取请求中的【条码/商品名】
		String itemBarcodeOrName = findStockRequest.getItemBarcodeOrName();
		//判断输入的是条码还是商品名
		if (FormatChecker.isNumber(itemBarcodeOrName)) {
			//输入条码，则按条码查询
			Item item = itemService.findItemByBarcode(itemBarcodeOrName);
			if (item == null)
				return new ResponseResult<>(10404, "Item Not Found");
			Stock stock = stockService.findStock(itemBarcodeOrName);
			if (stock == null)
				return new ResponseResult<>(10404, "Stock Not Found");
			Map<String, Object> findStockMap = new HashMap<>();
			String itemBarcode = item.getItemBarcode();
			Class<? extends Item> itemClass = item.getClass();
			Field[] itemClassDeclaredFields = itemClass.getDeclaredFields();
			for (Field field : itemClassDeclaredFields) {
				field.setAccessible(true);
				findStockMap.put(field.getName(), field.get(item));
				findStockMap.put("quantity", stock.getQuantity());
			}
			//如果相关新消息为
			Double slaesIn30Days = turnoverFlowService.findSalesIn30Days(itemBarcode);
			if (slaesIn30Days == null || slaesIn30Days.isNaN())
				findStockMap.put("slaesIn30Days", "/");
			else
				findStockMap.put("slaesIn30Days", slaesIn30Days);
			Supplier mainSupplier = supplierService.findMainSupplier(itemBarcode);
			if (mainSupplier == null)
				findStockMap.put("mainSupplierID", "/");
			else
				findStockMap.put("mainSupplierID", mainSupplier.getSupplierID());
			findStockList.add(findStockMap);
		} else {
			//输入商品名，则按商品名查询
			List<Item> itemList = itemService.findItemByName(itemBarcodeOrName);
			if (itemList.isEmpty())
				return new ResponseResult<>(10404, "Item Not Found");
			for (Item item : itemList) {
				String itemBarcode = item.getItemBarcode();
				Stock stock = stockService.findStock(itemBarcode);

				Map<String, Object> findStockMap = new HashMap<>();
				if (stock == null) {
					findStockMap.put("itemBarcodeOrName", itemBarcodeOrName);
					findStockList.add(findStockMap);
					return new ResponseResult<>(10404, "Stock Not Found", findStockList);
				}
				Class<? extends Item> itemClass = item.getClass();
				Field[] itemClassDeclaredFields = itemClass.getDeclaredFields();
				for (Field field : itemClassDeclaredFields) {
					field.setAccessible(true);
					findStockMap.put(field.getName(), field.get(item));
					findStockMap.put("quantity", stock.getQuantity());
				}
				Double slaesIn30Days = turnoverFlowService.findSalesIn30Days(itemBarcode);
				if (slaesIn30Days == null || slaesIn30Days.isNaN())
					findStockMap.put("slaesIn30Days", "/");
				else
					findStockMap.put("slaesIn30Days", slaesIn30Days);
				Supplier mainSupplier = supplierService.findMainSupplier(itemBarcode);
				if (mainSupplier == null)
					findStockMap.put("mainSupplier", "/");
				else
					findStockMap.put("mainSupplier", mainSupplier.getSupplierName());
				findStockList.add(findStockMap);
			}
		}
		return new ResponseResult<>(10200, "OK", findStockList);
	}

	/**
	 * 按条码查询带30天销量和主供应商的库存
	 *
	 * @param findStockRequest 请求体
	 * @return 响应体
	 */
	@Deprecated
	@PostMapping("/findStockByBarcodeWithSalesAndMainSupplier")
	public ResponseResult<Object> findStockByBarcodeWithSalesAndMainSupplier
	(@RequestBody FindStockRequest findStockRequest) throws IllegalAccessException {
		List<Object> findStockList = new ArrayList<>();
		String itemBarcode = findStockRequest.getItemBarcode();
		Item item = itemService.findItemByBarcode(itemBarcode);
		if (item == null)
			return new ResponseResult<>(10404, "Item Not Found");
		Stock stock = stockService.findStock(itemBarcode);
		if (stock == null)
			return new ResponseResult<>(10404, "Stock Not Found");
		Map<String, Object> findStockMap = new HashMap<>();
		Class<? extends Item> itemClass = item.getClass();
		Field[] itemClassDeclaredFields = itemClass.getDeclaredFields();
		for (Field field : itemClassDeclaredFields) {
			field.setAccessible(true);
			findStockMap.put(field.getName(), field.get(item));
		}
		findStockMap.put("quantity", stock.getQuantity());
		Double slaesIn30Days = turnoverFlowService.findSalesIn30Days(itemBarcode);
		if (slaesIn30Days == null || slaesIn30Days.isNaN()) findStockMap.put("slaesIn30Days", "/");
		else findStockMap.put("slaesIn30Days", slaesIn30Days);
		Supplier mainSupplier = supplierService.findMainSupplier(itemBarcode);
		if (mainSupplier == null) findStockMap.put("mainSupplierID", "/");
		else findStockMap.put("mainSupplierID", mainSupplier.getSupplierID());
		findStockList.add(findStockMap);
		return new ResponseResult<>(10200, "OK", findStockList);
	}

	/**
	 * 按名称查询带30天销量和主供应商的库存
	 *
	 * @param findStockRequest 请求体
	 * @return 响应体
	 */
	@Deprecated
	@PostMapping("/findStockByNameWithSalesAndMainSupplier")
	public ResponseResult<Object> findStockByNameWithSalesAndMainSupplier
	(@RequestBody FindStockRequest findStockRequest) throws IllegalAccessException {
		List<Object> findStockList = new ArrayList<>();
		String itemName = findStockRequest.getItemName();
		List<Item> itemList = itemService.findItemByName(itemName);
		if (itemList.isEmpty())
			return new ResponseResult<>(10404, "Item Not Found");
		for (Item item : itemList) {
			String itemBarcode = item.getItemBarcode();
			Stock stock = stockService.findStock(itemBarcode);
			Map<String, Object> findStockMap = new HashMap<>();
			if (stock == null) {
				findStockMap.put("itemBarcodeOrName", itemName);
				findStockList.add(findStockMap);
				return new ResponseResult<>(10404, "Stock Not Found", findStockList);
			}
			Class<? extends Item> itemClass = item.getClass();
			Field[] itemClassDeclaredFields = itemClass.getDeclaredFields();
			for (Field field : itemClassDeclaredFields) {
				field.setAccessible(true);
				findStockMap.put(field.getName(), field.get(item));
			}
			findStockMap.put("quantity", stock.getQuantity());
			Double slaesIn30Days = turnoverFlowService.findSalesIn30Days(itemBarcode);
			if (slaesIn30Days == null || slaesIn30Days.isNaN()) findStockMap.put("slaesIn30Days", "/");
			else findStockMap.put("slaesIn30Days", slaesIn30Days);
			Supplier mainSupplier = supplierService.findMainSupplier(itemBarcode);
			if (mainSupplier == null) findStockMap.put("mainSupplier", "/");
			else findStockMap.put("mainSupplier", mainSupplier.getSupplierName());
			findStockList.add(findStockMap);
		}
		return new ResponseResult<>(10200, "OK", findStockList);
	}

	/**
	 * 添加库存
	 *
	 * @param addStockRequest 请求体对象
	 * @return 响应体
	 */
	@PostMapping("/addStock")
	public ResponseResult<Object> addStock(@RequestBody AddStockRequest addStockRequest) {
		//获取请求体中的所有信息
		String itemBarcode = addStockRequest.getItemBarcode();
		String itemName = addStockRequest.getItemName();
		String supplierID = addStockRequest.getSupplierID();
		String unitOfMeasure = addStockRequest.getUnitOfMeasure();
		Double quantity = addStockRequest.getQuantity();
		Double purchasePrice = addStockRequest.getPurchasePrice();
		Double price = addStockRequest.getPrice();
		//检查供应商存在性
		if (supplierService.findSupplierById(supplierID) == null)
			return new ResponseResult<>(10404, "Supplier Not Found");
		//更新商品和库存
		Item item = itemService.findItemByBarcode(itemBarcode);
		Stock itemStock = stockService.findStock(itemBarcode);
		//自动添加不存在的商品
		if (item == null)
			itemService.addItem(itemBarcode, itemName, unitOfMeasure, purchasePrice, price);
		else
			itemService.changeItemPrice(itemBarcode, purchasePrice, price);
		//自动添加不存在的库存
		if (itemStock == null)
			stockService.addStock(itemBarcode, 0.0);
		//else stockService.changeStock(itemBarcode, quantity + itemStock.getQuantity());

		//获取批次时间并生成批号
		LocalDateTime batchDateTime = LocalDateTime.now();
		String year = String.format("%04d", batchDateTime.getYear());
		String month = String.format("%02d", batchDateTime.getMonthValue());
		String day = String.format("%02d", batchDateTime.getDayOfMonth());
		String hour = String.format("%02d", batchDateTime.getHour());
		String minute = String.format("%02d", batchDateTime.getMinute());
		String second = String.format("%02d", batchDateTime.getSecond());
		String nano = String.format("%09d", batchDateTime.getNano());
		String batchNo = year + month + day + hour + minute + second + nano;

		//生成进货流水
		supplementFlowService.addFlow(
				batchNo,
				batchDateTime,
				supplierID,
				itemBarcode,
				1,
				quantity,
				purchasePrice,
				null);

		//构造响应体
		SupplementFlow supplementFlow = new SupplementFlow(
				batchNo,
				batchDateTime,
				supplierID,
				itemBarcode,
				1,
				quantity,
				purchasePrice,
				null);
		return new ResponseResult<>(10200, "OK", supplementFlow);
	}

	/**
	 * 删除一定数量的单个商品库存
	 *
	 * @param deleteStockRequest 请求体对象
	 * @return 响应体
	 */
	@PostMapping("/deleteStock")
	public ResponseResult<Object> deleteStock(@RequestBody DeleteStockRequest deleteStockRequest) {
		//获取请求体类中的所有字段
		String itemBarcode = deleteStockRequest.getItemBarcode();
		String deleteStockRequestBatchNo = deleteStockRequest.getBatchNo();
		String supplierID = deleteStockRequest.getSupplierID();
		Double deleteStockRequestQuantity = deleteStockRequest.getQuantity();

		//检查商品、库存和供货商的存在性
		SupplementFlow flow = supplementFlowService.findFlow(deleteStockRequestBatchNo);
		if (flow == null)
			return new ResponseResult<>(10404, "Batch Not Found");
		Item item = itemService.findItemByBarcode(itemBarcode);
		if (item == null)
			return new ResponseResult<>(10404, "Item Not Found");
		Stock itemStock = stockService.findStock(itemBarcode);
		if (itemStock == null)
			return new ResponseResult<>(10404, "Stock Not Found");
		Supplier supplier = supplierService.findSupplierById(supplierID);
		if (supplier == null)
			return new ResponseResult<>(10404, "Supplier Not Found");

		//检查对应流水的进货量是否够减
		Double restQuantity = supplementFlowService.findRestQuantity(deleteStockRequestBatchNo, itemBarcode);
		if (deleteStockRequestQuantity > restQuantity)
			return new ResponseResult<>(10412, "Quantity Overflows");
		//stockService.changeStock(itemBarcode, itemStock.getQuantity() - deleteStockRequestQuantity);

		//获取批次时间
		LocalDateTime batchDateTime = LocalDateTime.now();

		//生成批号
		String year = String.format("%04d", batchDateTime.getYear());
		String month = String.format("%02d", batchDateTime.getMonthValue());
		String day = String.format("%02d", batchDateTime.getDayOfMonth());
		String hour = String.format("%02d", batchDateTime.getHour());
		String minute = String.format("%02d", batchDateTime.getMinute());
		String second = String.format("%02d", batchDateTime.getSecond());
		String nano = String.format("%09d", batchDateTime.getNano());
		String batchNo = year + month + day + hour + minute + second + nano;

		SupplementFlow specificFlow = supplementFlowService.findSpecificFlow(deleteStockRequestBatchNo, itemBarcode);
		//生成退货流水
		supplementFlowService.addFlow(batchNo,
				batchDateTime,
				supplierID,
				itemBarcode,
				-1,
				deleteStockRequestQuantity,
				specificFlow.getPurchasePrice(),
				deleteStockRequestBatchNo);

		return new ResponseResult<>(10200, "OK");
	}

	/**
	 * 删除一定数量的多个商品库存
	 *
	 * @param deleteStockRequests 请求体对象
	 * @return n响应体
	 */
	@Deprecated
	@PostMapping("/deleteStocks")
	public ResponseResult<Object> deleteStocks(@RequestBody DeleteStockRequest[] deleteStockRequests) {
		Map<String, Object> batchNotFoundMap = new HashMap<>();
		Map<String, Object> itemNotFoundMap = new HashMap<>();
		Map<String, Object> stockNotFoundMap = new HashMap<>();
		Map<String, Object> supplierNotFoundMap = new HashMap<>();
		Map<String, Object> stockNotEnoughMap = new HashMap<>();

		//异常检查
		for (DeleteStockRequest deleteStockRequest : deleteStockRequests) {
			//获取请求体类中的所有字段
			String itemBarcode = deleteStockRequest.getItemBarcode();
			String deleteStockRequestBatchNo = deleteStockRequest.getBatchNo();
			String supplierID = deleteStockRequest.getSupplierID();
			Double deleteStockRequestQuantity = deleteStockRequest.getQuantity();

			//检查流水、商品、库存和供货商的存在性
			SupplementFlow flow = supplementFlowService.findFlow(deleteStockRequestBatchNo);
			if (flow == null) {
				batchNotFoundMap.put("batchNo", deleteStockRequestBatchNo);
				return new ResponseResult<>(10404, "Batch Not Found", batchNotFoundMap);
			}
			Item item = itemService.findItemByBarcode(itemBarcode);
			if (item == null) {
				itemNotFoundMap.put("itemBarcode", itemBarcode);
				return new ResponseResult<>(10404, "Item Not Found", itemNotFoundMap);
			}
			Stock itemStock = stockService.findStock(itemBarcode);
			if (itemStock == null) {
				stockNotFoundMap.put("itemBarcode", itemBarcode);
				return new ResponseResult<>(10404, "Stock Not Found", stockNotFoundMap);
			}
			Supplier supplier = supplierService.findSupplierById(supplierID);
			if (supplier == null) {
				supplierNotFoundMap.put("supplierID", supplierID);
				return new ResponseResult<>(10404, "Supplier Not Found", supplierNotFoundMap);
			}

			//检查对应流水的进货量是否够减
			Double restQuantity = supplementFlowService.findRestQuantity(deleteStockRequestBatchNo, itemBarcode);
			if (deleteStockRequestQuantity > restQuantity) {
				stockNotEnoughMap.put("batchNo", deleteStockRequestBatchNo);
				stockNotEnoughMap.put("flowQuantity", restQuantity);
				return new ResponseResult<>(10412, "Quantity Overflows", stockNotEnoughMap);
			}
		}

		//获取批次时间
		LocalDateTime batchDateTime = LocalDateTime.now();
		//生成批号
		String year = String.format("%04d", batchDateTime.getYear());
		String month = String.format("%02d", batchDateTime.getMonthValue());
		String day = String.format("%02d", batchDateTime.getDayOfMonth());
		String hour = String.format("%02d", batchDateTime.getHour());
		String minute = String.format("%02d", batchDateTime.getMinute());
		String second = String.format("%02d", batchDateTime.getSecond());
		String nano = String.format("%09d", batchDateTime.getNano());
		String batchNo = year + month + day + hour + minute + second + nano;

		//循环删除
		for (DeleteStockRequest deleteStockRequest : deleteStockRequests) {
			//获取请求体类中的相关字段
			String deleteStockRequestBatchNo = deleteStockRequest.getBatchNo();
			String itemBarcode = deleteStockRequest.getItemBarcode();
			String supplierID = deleteStockRequest.getSupplierID();
			Double deleteStockRequestQuantity = deleteStockRequest.getQuantity();

			/*
			更新库存
			double newQuantity = stockService.findStock(itemBarcode).getQuantity() - deleteStockRequestQuantity;
			stockService.changeStock(itemBarcode, newQuantity);
			 */

			SupplementFlow specificFlow = supplementFlowService.findSpecificFlow(deleteStockRequestBatchNo, itemBarcode);
			//生成退货流水
			supplementFlowService.addFlow(batchNo,
					batchDateTime,
					supplierID,
					itemBarcode,
					-1,
					deleteStockRequestQuantity,
					specificFlow.getPurchasePrice(),
					deleteStockRequestBatchNo);
		}
		return new ResponseResult<>(10200, "OK");
	}

}
